import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mdpro.settings")
import django
django.setup()

from goods.models import CateChannel, CateGroup, Cate

cate_list = Cate.objects.all()
channel_list = CateChannel.objects.all()
group_list = CateGroup.objects.all()
print(cate_list)
print(channel_list)
print(group_list)

def xTree(datas):
    lists=[]
    tree={}
    parent_id=''
    for i in datas:
        item=i
        tree[item['id']]=item
    root=None
    for i in datas:
        obj=i
        if not obj['cid']:
            root=tree[obj['id']]
            lists.append(root)
        else:
            parent_id=obj['cid']
            if 'childlist' not in tree[parent_id]:
                tree[parent_id]['childlist']=[]
            tree[parent_id]['childlist'].append(tree[obj['id']])
    return lists


